
/****** Object:  StoredProcedure [proc_CustomerOrdersLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerOrdersLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerOrdersLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_CustomerOrdersLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[OrderNo],
		[CustomerID],
		[CustomerAddress],
		[CustomerName],
		[CustomerPhone],
		[PreferredShipDate],
		[ShipAddress],
		[Note],
		[ShipDate],
		[PaymentMethodID],
		[TotalAmount],
		[GST],
		[StatusID],
		[InvoiceID],
		[Deleted],
		[CreatedDate],
		[LastModifiedDate],
		[LastModifiedByUser],
		[LastModifiedByCustomer],
		[BranchID],
		[VoucherID]
	FROM [CustomerOrders]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerOrdersLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerOrdersLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerOrdersLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerOrdersLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerOrdersLoadAll];
GO

CREATE PROCEDURE [proc_CustomerOrdersLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[OrderNo],
		[CustomerID],
		[CustomerAddress],
		[CustomerName],
		[CustomerPhone],
		[PreferredShipDate],
		[ShipAddress],
		[Note],
		[ShipDate],
		[PaymentMethodID],
		[TotalAmount],
		[GST],
		[StatusID],
		[InvoiceID],
		[Deleted],
		[CreatedDate],
		[LastModifiedDate],
		[LastModifiedByUser],
		[LastModifiedByCustomer],
		[BranchID],
		[VoucherID]
	FROM [CustomerOrders]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerOrdersLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerOrdersLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerOrdersUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerOrdersUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerOrdersUpdate];
GO

CREATE PROCEDURE [proc_CustomerOrdersUpdate]
(
	@ID int,
	@OrderNo char(10),
	@CustomerID int = NULL,
	@CustomerAddress nvarchar(200) = NULL,
	@CustomerName nvarchar(50) = NULL,
	@CustomerPhone nvarchar(20) = NULL,
	@PreferredShipDate datetime = NULL,
	@ShipAddress nvarchar(200),
	@Note nvarchar(MAX) = NULL,
	@ShipDate datetime = NULL,
	@PaymentMethodID int = NULL,
	@TotalAmount numeric(18,2),
	@GST numeric(18,2),
	@StatusID int,
	@InvoiceID int = NULL,
	@Deleted bit,
	@CreatedDate datetime,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@LastModifiedByCustomer int = NULL,
	@BranchID int,
	@VoucherID uniqueidentifier = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [CustomerOrders]
	SET
		[OrderNo] = @OrderNo,
		[CustomerID] = @CustomerID,
		[CustomerAddress] = @CustomerAddress,
		[CustomerName] = @CustomerName,
		[CustomerPhone] = @CustomerPhone,
		[PreferredShipDate] = @PreferredShipDate,
		[ShipAddress] = @ShipAddress,
		[Note] = @Note,
		[ShipDate] = @ShipDate,
		[PaymentMethodID] = @PaymentMethodID,
		[TotalAmount] = @TotalAmount,
		[GST] = @GST,
		[StatusID] = @StatusID,
		[InvoiceID] = @InvoiceID,
		[Deleted] = @Deleted,
		[CreatedDate] = @CreatedDate,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[LastModifiedByCustomer] = @LastModifiedByCustomer,
		[BranchID] = @BranchID,
		[VoucherID] = @VoucherID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerOrdersUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerOrdersUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_CustomerOrdersInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerOrdersInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerOrdersInsert];
GO

CREATE PROCEDURE [proc_CustomerOrdersInsert]
(
	@ID int = NULL output,
	@OrderNo char(10),
	@CustomerID int = NULL,
	@CustomerAddress nvarchar(200) = NULL,
	@CustomerName nvarchar(50) = NULL,
	@CustomerPhone nvarchar(20) = NULL,
	@PreferredShipDate datetime = NULL,
	@ShipAddress nvarchar(200),
	@Note nvarchar(MAX) = NULL,
	@ShipDate datetime = NULL,
	@PaymentMethodID int = NULL,
	@TotalAmount numeric(18,2),
	@GST numeric(18,2),
	@StatusID int,
	@InvoiceID int = NULL,
	@Deleted bit,
	@CreatedDate datetime,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@LastModifiedByCustomer int = NULL,
	@BranchID int,
	@VoucherID uniqueidentifier = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [CustomerOrders]
	(
		[OrderNo],
		[CustomerID],
		[CustomerAddress],
		[CustomerName],
		[CustomerPhone],
		[PreferredShipDate],
		[ShipAddress],
		[Note],
		[ShipDate],
		[PaymentMethodID],
		[TotalAmount],
		[GST],
		[StatusID],
		[InvoiceID],
		[Deleted],
		[CreatedDate],
		[LastModifiedDate],
		[LastModifiedByUser],
		[LastModifiedByCustomer],
		[BranchID],
		[VoucherID]
	)
	VALUES
	(
		@OrderNo,
		@CustomerID,
		@CustomerAddress,
		@CustomerName,
		@CustomerPhone,
		@PreferredShipDate,
		@ShipAddress,
		@Note,
		@ShipDate,
		@PaymentMethodID,
		@TotalAmount,
		@GST,
		@StatusID,
		@InvoiceID,
		@Deleted,
		@CreatedDate,
		@LastModifiedDate,
		@LastModifiedByUser,
		@LastModifiedByCustomer,
		@BranchID,
		@VoucherID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerOrdersInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerOrdersInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerOrdersDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerOrdersDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerOrdersDelete];
GO

CREATE PROCEDURE [proc_CustomerOrdersDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [CustomerOrders]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerOrdersDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerOrdersDelete Error on Creation'
GO
